package cn.biplam.front.template.base;

import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.HtmlImage;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Border_Style;
import cn.biplam.front.html.base.Const.Window_Event;

/**
 * 20x20大小的图片按钮(默认分页栏背景色之上)
 * @author XiaoRuxing Nov 18, 20093:10:54 PM
 * @version 1.0
 */
public class ButtonImageHorizon {

	private HtmlDiv button;
	private String ID=null;
	private String imageUrl;
	private String btTitle=null;
	private String clickScript;
	private String mouseOutColor= "#D1DFF0";
	private String mouseOverColor= "#F0F5FA";

	/**
	 * 构造方法
	 * @param imageUrl	按钮图片
	 */
	public ButtonImageHorizon(String imageUrl){
		this(null,imageUrl);
	}

	/**
	 * 构造方法
	 * @param ID		页面ID
	 * @param imageUrl	按钮图片
	 */
	public ButtonImageHorizon(String ID,String imageUrl){
		this(ID,imageUrl,null);
	}

	/**
	 *  创建24x20图片按钮
	 * @param ID          页面ID
	 * @param imageUrl    图片URL
	 * @param btTitle     按钮标题
	 */
	public ButtonImageHorizon(String ID, String imageUrl, String btTitle){
		this.ID = ID;
		this.imageUrl = imageUrl;
		this.btTitle = btTitle;
	}
	
	/**
	 *  设置点击事件脚本
	 * @param bindScript 点击事件脚本
	 */
	public void setOnClickScript(String bindScript){
		this.clickScript = bindScript;
	}

	/**
	 * 返回设置好的Html控件
	 * @return	HtmlWindow
	 * @throws ErrorMessage 
	 */
	public HtmlWindow get() throws ErrorMessage{
		this.button=new HtmlDiv(ID,"pib");
		
		
		HtmlImage messageImage = new HtmlImage(this.imageUrl,"pi");
		messageImage.setTitle(this.btTitle);
		messageImage.setBorder("1", Border_Style.Solid, mouseOutColor);
		this.button.put(messageImage);
		
		if(this.clickScript!=null){
			this.button.bind(Window_Event.OnClick,clickScript);
			messageImage.bind(Window_Event.OnMouseOut, "this.style.border='1px solid "+mouseOutColor+"';");
			messageImage.bind(Window_Event.OnmouseOver, "this.style.border='1px solid "+mouseOverColor+"';");
		}

		return this.button;
	}

	public void setMouseOutColor(String mouseOutColor) {
		this.mouseOutColor = mouseOutColor;
	}

	public void setMouseOverColor(String mouseOverColor) {
		this.mouseOverColor = mouseOverColor;
	}
}
